import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Cuervo here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Cuervo extends Enemigos
{
     private boolean facingLeft;
     private int Speed;
     private int animationCounter;
     private final GreenfootImage cuervoL = new GreenfootImage("Cuervo.png");
     private final GreenfootImage cuervoL0 = new GreenfootImage("Cuervo0.png");
     private final GreenfootImage cuervoR = new GreenfootImage(cuervoL);
     private final GreenfootImage cuervoR0 = new GreenfootImage(cuervoL0);
     private Ninja ninja;
     private GreenfootSound DagaEncajada;
    
    
     public Cuervo(){
       Speed = 3;
       animationCounter = 0;
       facingLeft = true;
       
       cuervoR.mirrorHorizontally();
       cuervoR0.mirrorHorizontally();
       
       DagaEncajada = new GreenfootSound("DagaEncajada.wav"); 
        }
     
     /**
     * Act - do whatever the Cuervo wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        mueve();
        checaLimite();
        checaColision();
        
        } 
    
     /**
     * Mueve Cuervo hacia la Izquierda 
     */
    public void mueve(){
        
        setLocation (this.getX() - Speed, this.getY());
         animationCounter ++;    
        if(animationCounter < 8){
            
            if(facingLeft)
             setImage(cuervoL0);
            else
              setImage(cuervoR0);
              
        }else if(animationCounter < 16){
             
            if(facingLeft)
             setImage(cuervoL);
            else
              setImage(cuervoR);
              
        }else if(animationCounter == 16)
              animationCounter = 0;
              
       }
    
    public void checaLimite(){        
                
                  if(getX()< 5  ){
                     Speed = -Speed;
                     facingLeft = false;
                   } else if(getX() > getWorld().getWidth()-5){
                       Speed = -Speed;
                       facingLeft = true;
                    
                    }           
                }
                
    public void checaColision(){
        
        Niveles mundo = (Niveles)this.getWorld();
        ninja = mundo.ninja;
              
        if(isTouching(Daga.class)){
         ninja.aumentaPuntos(10);
         DagaEncajada.play();
         removeTouching(Daga.class);
         getWorld().removeObject(this);
                } 
    
      }
      
    public boolean regresaFacingLeft(){
      return   facingLeft;  
    }
    
}
